<template>
  <div>
    <h1>Token: {{ token ? token : '未登录' }}</h1>
    <button v-if="token" @click="logout">退出登录</button>
  </div>
</template>

<script>
import Cookies from "js-cookie";
import {login, logout} from "@/api";

export default {
  name: 'Home',
  data() {
    return {
      token: Cookies.get('lc-auth-token')
    }
  },
  methods: {
    logout() {
      // 根据真实场景确定是否需要传userId, 一版在后端获取当前登录的用户ID
      logout().then(() => {
        Cookies.remove('lc-auth-token');
        login();
      })
    }
  }
}
</script>

<style scoped>

</style>
